**************************************************
***this estimates the main text, table 1 models
**************************************************

**************************************************
*** set your working directory appropriately
**************************************************

cd ""

**************************************************
*** read in the data
**************************************************
save "replicationData", replace

*****************************************************
*** we have to generate our seat share measure first
*****************************************************

	egen sum22=total(Perc_seats_LH), by(newpid)
	gen SSseats=Perc_seats_LH/sum22
	
*****************************************************
*** and now to generate our cabinet share measure
*****************************************************

gen inGov = Prime_minister == 1 | cabinet_partner == 1
egen totalCabSeats=total(SSseats) if inGov == 1, by(pid)
egen totalOppSeats=total(SSseats) if inGov == 0, by(pid)
gen cabSeatShare = SSseats / totalCabSeats
gen oppSeatShare = SSseats / totalOppSeats
recode cabSeatShare . = 0
recode oppSeatShare . = 0

**************************************************
*** estimate the main models and save the results
**************************************************		

**************************************************
*Denmark
**************************************************
		capture drop pdummy*
		capture drop ref_pdummy		
		tab partyname if Country == 3, g(pdummy) 
		rename pdummy7 ref_pdummy
		rename pdummy8 pdummy7
		rename pdummy9 pdummy8

		meoprobit Resp_attribution Prime_minister cabinet_partner Opposition ///
									affinity median_dummy centrality ///
									banz SSseats cabSeatShare pdummy* if Country == 3 || pid:
		estimates store DK, title(Dk)				
		
**************************************************
***Germany
**************************************************
		capture drop pdummy*
		capture drop ref_pdummy		
		tab partyname if Country == 1, g(pdummy)	
		rename pdummy2 ref_pdummy
		rename pdummy3 pdummy2
		rename pdummy4 pdummy3
		rename pdummy5 pdummy4
		rename pdummy6 pdummy5
		rename pdummy7 pdummy6

		meoprobit Resp_attribution Prime_minister cabinet_partner Opposition ///
									affinity median_dummy centrality ///
									banz SSseats cabSeatShare pdummy* if Country == 1 || pid:
		estimates store GE, title(GE)

**************************************************
***Italy
**************************************************
		capture drop pdummy*
		capture drop ref_pdummy		
		tab partyname if Country == 2, g(pdummy) 
		rename pdummy7 ref_pdummy
		rename pdummy8 pdummy7
		rename pdummy9 pdummy8
		rename pdummy10 pdummy9

		meoprobit Resp_attribution Prime_minister cabinet_partner Opposition ///
									affinity median_dummy centrality ///
									banz SSseats cabSeatShare pdummy* if Country == 2 || pid:
		estimates store IT, title(IT)
				
**************************************************
***Netherlands
**************************************************
		capture drop pdummy*
		capture drop ref_pdummy
		tab partyname if Country == 4, g(pdummy)	
		rename pdummy10 ref_pdummy		

		meoprobit Resp_attribution Prime_minister cabinet_partner Opposition ///
									affinity median_dummy centrality ///
									banz SSseats cabSeatShare pdummy* if Country == 4 || pid:
		estimates store NL, title(NL)

**************************************************
***UK
**************************************************
		capture drop pdummy*
		capture drop ref_pdummy
		tab partyname if Country == 6 , g(pdummy) 		
		drop pdummy1 		//BNP drops out of analysis
		drop pdummy8 		//UKIP drops out of analysis
		rename pdummy2 ref_pdummy
		rename pdummy3 pdummy1
		rename pdummy4 pdummy2
		rename pdummy5 pdummy3
		rename pdummy6 pdummy4
		rename pdummy7 pdummy5

		meoprobit Resp_attribution Prime_minister cabinet_partner Opposition ///
									affinity median_dummy centrality ///
									banz SSseats cabSeatShare pdummy*  if Country == 6 || pid:
		estimates store UK, title(UK)
		estout DK GE IT NL UK using "mainText.doc" , cells(b(fmt(2)star) se(par fmt(2))) stats(N ll) style(fixed) replace 

**************************************************
*** and we're finished
**************************************************
